﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;

public partial class FilesDownLoad : System.Web.UI.Page
{
    FileDownLoadComm help = new FileDownLoadComm();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.Request.QueryString["filePosition"] != null)
        {
            string filePosition = Page.Request.QueryString["filePosition"].ToString();
            string pathL = Server.MapPath("~/" + filePosition);
            string fileName = filePosition.Substring(filePosition.LastIndexOf("/") + 1);
            FileInfo fiL = new FileInfo(pathL);

            if (fiL.Exists)
            {
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8).ToString());
                Response.AddHeader("Content-Length", fiL.Length.ToString());
                Response.ContentType = "application/octec-stream;charset=gb2312";
                Response.Filter.Close();
                Response.WriteFile(fiL.FullName);
                Response.End();
            }
            else
            {
                Response.Write("<script language=javascript>alert('" + fileName + " 不存在或者无权访问！！');</script>");
            }
        }
        Response.Write("<script language=javascript>history.back(0);</script>");
    }
    
        //FileDownLoadModel model = new FileDownLoadModel();
        //model.ContractNoMain = "";
        //model.FileName = "";
        //model.SoNo = "";
        //model.UserCode = "";
        //model.FilePosition = filePosition;
        //help.FileDownload(this, model);
}